import { createStore } from 'vuex'
import list from './module/list'
/**
 * state 访问
 * $store.state.name
 *
 * this.$store.state.name
 *
 * mapState(['name'])
 * mapState({name:'name'})
 *
 * mutations 访问方法
 * this.$store.commit('方法名如setAge',参数)
 * **/
export default createStore({
  //状态值
  state: {
    count:0,
    name:"jack",
    age:1000,
    sex:'male',
    info:''
  },
  //状态派生
  getters: {
    // getSex(state,id){
    //   return "【"+state.sex+"】"+id;
    // }
    getSex:(state)=>(id)=>{
      return "【"+state.sex+"】"+id;
    }
  },
  //修改状态
  mutations: {
    increment(state,e){
      console.log(state)
      state.count++
      console.log(e)
    },
    setAge(state,val){
      state.age=val
    },
    setInfo(state,val){
      state.info=val
    }
  },

  actions: {
    setInfo(c){

      setTimeout(()=>{

        c.commit("setInfo","我是actons里的异步提交");
      },1000)
    }
  },

  modules: {
    list:list
  }
})
